from core.basehandler import BaseHandler
from core.room import Room
from core.action import Action
from core.support import get_game

class Lion(Room):
    def __init__(self, room_id):
        Room.__init__(self, room_id)    # do basic initialization for every room
        
        # add inventory items
        #self.add_item(Keys())
        
        # build list of actions
        self.add_action(Walk_away)
        self.add_action(Shoot_it)
    
    # return description of room.
    def get_description(self):
        return "You come upon a lone lion, he doesn't seem too big. What will you do?"
    
    # return image of room
    def get_image(self):
        return 'lion.jpg'

    def gun_has_bullets(self):
        game = get_game()
        player = game.get_player()
        if 'gun' in player.inventory:
            #if player.inventory['gun'].bullets:
            if player.inventory['gun'].bullets >0:
                return True
            else: 
                return False

class LionHandler(BaseHandler):
    
    # return class to use to create a new instance of this room
    def get_room_class(self):
        return Lion

# define actions for this room

class Walk_away(Action):
    def __init__(self):
        Action.__init__(self, "Walk_away")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Walk Away"
    
    # return id of room to enter when action is complete
    def get_destination(self):
        return 'bush3'
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "get"

class Shoot_it(Action):
    def __init__(self):
        Action.__init__(self, "Shoot_it")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Shoot it"
    
    def is_enabled(self):
        if self.room.gun_has_bullets():
            return True
        else:
            return False
    

        
    # return id of room to enter when action is complete
    def get_destination(self):
        #update bullet count first
        game = get_game()
        player = game.get_player()
        #player.inventory['gun'].bullets=False
        player.inventory['gun'].bullets=player.inventory['gun'].bullets-1
        return 'lion_pride'
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "get"